//
//  wingbeat_param.cpp
//  template4
//
//  Created by Xiaochen Lian on 5/16/12.
//  Copyright (c) 2012 University of California, Los Angeles. All rights reserved.
//

#include "wingbeat_param.h"

void IWingbeat_param::set_u(GLfloat u_d, GLfloat u_u)
{
    u[0] = u_d;
    u[1] = u_u;
}

void IWingbeat_param::set_u(GLfloat* u)
{
    this->u[0] = u[0];
    this->u[1] = u[1];
}

CGOne::CGOne(GLfloat q_min, GLfloat q_max, GLfloat u_d, GLfloat u_u)
{
    u[0] = u_d;
    u[1] = u_u;
    q[0] = q_min;
    q[1] = q_max;
}

CGOne::CGOne(GLfloat q_min, GLfloat q_max, GLfloat* u)
{
    this->u[0] = u[0];
    this->u[1] = u[1];
    q[0] = q_min;
    q[1] = q_max;
}

GLfloat CGOne::comp_func(GLfloat phi)
{
    GLfloat r = (u[1]-u[0])*(1+cos(phi))*0.5 + u[0];
    return q[0] + (q[1]-q[0])*r;
}

CGTwo::CGTwo(GLfloat q_min, GLfloat q_max, GLfloat u_d, GLfloat u_u)
{
    u[0] = u_d;
    u[1] = u_u;
    q[0] = q_min;
    q[1] = q_max;
}

CGTwo::CGTwo(GLfloat q_min, GLfloat q_max, GLfloat* u)
{
    this->u[0] = u[0];
    this->u[1] = u[1];
    q[0] = q_min;
    q[1] = q_max;
}


GLfloat CGTwo::comp_func(GLfloat phi)
{
    GLfloat r;
    if (abs(phi) < M_PI)
        r = u[0];
    else
        r = (u[1]-u[0])*(1-cos(2*phi))*0.5 + u[0];
    
    return q[0] + (q[1]-q[0])*r;
}